package com.d0330.homework;

import java.util.Iterator;
import java.util.TreeSet;

public class TestBankcard {
    public static void main(String[] args) {
        TreeSet<Account> set1 = new TreeSet<>();//集合
        TreeSet<Account> set2 = new TreeSet<>();
        String[] names = {"张三", "李四"};
        for (int i = 0; i < 100; i++) {
            String name = names[(int) (Math.random() * 2)];//随机输出名字
            int money = (int) (Math.random() * 10000) + 1;//随机产生钱数
            Account account = new Account(name, money);//创建一个对象
            if (name.equals("张三")) {
                set1.add(account);
            }
            if (name.equals("李四")) {
                set2.add(account);
            }
        }
//        System.out.println(set1.size()+" "+set2.size());
        Iterator i1 = set1.iterator();
        Iterator i2 = set2.iterator();
        while (i1.hasNext()) {
            System.out.println(i1.next());
        }
        while (i2.hasNext()) {
            System.out.println(i2.next());
        }
        System.out.println("获取结果为：");
        if (set1.size() > set2.size()) {
            System.out.println("张三消费次数最多，最高消费金额为" + set1.iterator().next().getMoney());
        }
        if (set1.size() < set2.size()) {
            System.out.println("张三消费次数最多，最高消费金额为" + set2.iterator().next().getMoney());
        }
    }
}
